#include "read_config.hpp"
#include <fstream>
#include <iostream>

bool read_video_record_param(std::string str_config_file_path,
	SVideoRecordParam &param)
{
	std::ifstream config_file(str_config_file_path.c_str());
	if (!config_file.is_open()) {
		std::cerr << "can not open the config file: " 
			<< str_config_file_path << std::endl;
		return false;
	}
	Json::Reader reader;
	Json::Value root;
	if (!reader.parse(config_file, root)) {
		std::cerr << "parse config file failed, error msg: " << std::endl;
		std::cerr << reader.getFormattedErrorMessages() << std::endl;
		return false;
	}
	std::string str_video_stream_path = root.get("videoStreamPath", "").asString();
	if (str_video_stream_path.empty()) {
		std::cerr << "read config file, get videoStreamPath failed." << std::endl;
		return false;
	}
	std::string str_save_folder = root.get("saveFolder", "").asString();
	if (str_save_folder.empty()) {
		std::cerr << "read config file, get saveFolder failed." << std::endl;
		return false;
	}
	int video_save_minutes = root.get("videoSaveMinutes", -1).asInt();
	if (video_save_minutes == -1) {
		std::cerr << "read config file, get videoSaveMinutes failed." << std::endl;
		return false;
	}
	param.str_video_stream_path_ = str_video_stream_path;
	param.str_save_folder_ = str_save_folder;
	param.video_save_minutes_ = video_save_minutes;
	return true;
}